package cn.fxl.controller;

import cn.fxl.ajax.AjaxResult;
import cn.fxl.domain.BuyMovieDto;
import cn.fxl.domain.MoveUser;
import cn.fxl.domain.Movie;
import cn.fxl.service.IMovieService;
import cn.fxl.service.IMovieUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class MovieController {
    @Autowired
    private IMovieService iMovieService;
    @Autowired
    private IMovieUserService iMovieUserService;
    @GetMapping("/movie/getAll")
    public List<Movie> movieGetAll(){
        return iMovieService.getAll();
    }

    @PostMapping("/buymovie")
    public AjaxResult buymovie(@RequestBody BuyMovieDto buyMovieDto){
        try {
          return iMovieService.buymovie(buyMovieDto);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"失败");
        }
    }
    @GetMapping("/getOne/{id}")
    public Movie getOne(@PathVariable("id") Long id){
       return iMovieService.getOne(id);
    }

    @GetMapping("/move/getOne/{id}")
    public AjaxResult moveGetOne(@PathVariable("id") Long id){
        return iMovieUserService.moveGetOne(id);
    }
//   movieFeign.saveAdd(moveUser);
    @PostMapping("/saveAdd")
    public AjaxResult saveAdd(@RequestBody MoveUser moveUser){
        try {
            iMovieUserService.saveAdd(moveUser);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"失败");
        }
    }
    //        movieFeign.UpdateByMovie(movie);
    @PostMapping("/UpdateByMovie")
    public AjaxResult UpdateByMovie(@RequestBody Movie movie){
        try {
            iMovieService.UpdateByMovie(movie);
         return    new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"失败");
        }
    }
}
